package com.example.myapplication.base;


import java.util.ArrayList;

public abstract class BasePresenter<V extends BaseView> {
    private ArrayList<BaseModel> list;
    public V mView;

    public BasePresenter() {
        initModel();
    }

    protected abstract void initModel();

    public void bindView(V view) {

        mView = view;
    }

    public void addModel(BaseModel baseModel) {
        if (list == null) {
            list = new ArrayList<>();
        }
        list.add(baseModel);
    }

    public void destroy() {
        //将持有的V层对象释放,避免内存泄漏
        mView = null;
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                list.get(i).destroy();
            }
        }
    }
}
